feat(speech): add async and WebSocket TTS operations - #223
Conversation
Add the missing MiniMax TTS operations to the speech command and SDK: - mmx speech async: create a long-form async TTS task (POST /v1/t2a_async_v2) - mmx speech task get: query async task status (GET /v1/query/t2a_async_query_v2) - mmx speech websocket: synchronous streaming TTS over WSS (/ws/v1/t2a_v2) - SpeechSDK: createAsync, queryAsync, downloadAsyncFile, synthesizeWebSocket The async flow polls the task to completion and downloads the resulting audio file; the WebSocket flow streams hex-encoded audio chunks as they arrive and saves or pipes them.
NianJiuZst
left a comment
There was a problem hiding this comment.
Thanks for adding the missing async and WebSocket TTS surfaces. I do not think this is ready to merge yet because the async path diverges from the current official API contract in three blocking places:
-
The speech async --wait download is unauthenticated.
src/commands/speech/async.ts passes the protected /v1/files/retrieve_content URL to the generic downloadFile helper, which performs a bare fetch without an Authorization header. A successful async task will therefore fail at the final download step with 401. The official Retrieve Content API requires Bearer authentication:
https://platform.minimax.io/docs/api-reference/file-management-retrieve-content -
The async request uses the wrong sample-rate field.
The new async request type reuses the synchronous HTTP TTS audio_setting shape and sends sample_rate. The async endpoint expects audio_sample_rate, so the new --sample-rate option is not wired to the documented request contract. See the official async-create request example:
https://platform.minimax.io/docs/api-reference/speech-t2a-async-create -
The advertised 1M-character path is not implemented.
--text-file currently reads the local file and sends its contents as text. The official API limits direct text input to 50,000 characters; the larger long-form path requires uploading a file with purpose t2a_async_input and passing text_file_id. Neither the CLI nor SpeechAsyncRequest currently supports that path:
https://platform.minimax.io/docs/api-reference/speech-t2a-async-create
I verified this on head ed939d1. Typecheck, lint, build, the 11 new focused tests, and GitHub CI pass, but the tests only exercise permissive mocks. A request-capture reproduction on the actual command path observed audio_setting.sample_rate and a null download authorization header.
Please fix these contracts and add regression coverage that asserts audio_sample_rate, authenticated content retrieval, and the text_file_id long-text flow before merging.
Reason: Add the missing async and WebSocket TTS operations to the speech CLI and SDK.
Changes
mmx speech async— create a long-form async TTS task via POST/v1/t2a_async_v2(textToAudioAsyncCreate). With--waitit polls until completion and downloads the audio.mmx speech task get— query async TTS task status viaGET /v1/query/t2a_async_query_v2(textToAudioAsyncQuery).mmx speech websocket— synchronous streaming TTS over WSS/ws/v1/t2a_v2(textToAudioWebSocket). Supports--outto save the audio and--streamto pipe raw audio chunks to stdout.SpeechSDK.createAsync,SpeechSDK.queryAsync,SpeechSDK.downloadAsyncFile, andSpeechSDK.synthesizeWebSocket.Checks
bun run typecheck— passbun run lint— passbun test— 460 passingbun run build— passNeed help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.